﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
using ESF.General.Entity;
using ESF.General;
using ESF.MSReporting;
using ESF.Web;
using ESF.SSO.Core.DataAccess;
using ESF.SSO.Core.Entities.Log;
using ESF.SSO.Core.BusinessLogic;

#endregion


public partial class Reports_frmReportViewer : ReportViewerBasePage
{
	#region Funciones

	protected override object GetLocalReportDataSet(string pReportServerURL, string pReportFolderPath, object pExtraData)
	{
		List<ReportParameter> parameters;


		parameters = pExtraData as List<ReportParameter>;

		switch (pReportFolderPath.ToUpper())
		{
			case "~/REPORTS/USERS/OPERATIONEXECUTIONSTATISTICS":
				
				return CtrlStatistics.BrowseTable (
					new ESF.SSO.Core.Entities.Statistics.OperationExecution ()
					{
						User = new ESF.SSO.Core.Entities.User () { Alias = GetValueFromParams (parameters, "pUserAlias") },
						filExecutionDateTimeStart = TextHelper.GetNullableDate (GetValueFromParams (parameters, "pStartDate")),
						filExecutionDateTimeEnd = TextHelper.GetNullableDate (GetValueFromParams (parameters, "pEndDate"))
					});

			case "~/REPORTS/USERS/USERSONLINE":
				
				return DataHelper.ToDataSet (AdoUserSessionLog.GetUsersOnline ());

			case "~/REPORTS/USERS/USERSESSIONS":

				return DataHelper.ToDataSet (AdoUserSessionLog.GetUserSessions (
					new UserSessionLog ()
					{
						User = new ESF.SSO.Core.Entities.User () { Alias = GetValueFromParams (parameters, "pUserAlias") },
						StartDateTime = TextHelper.GetNullableDate (GetValueFromParams (parameters, "pStartDate")),
						EndDateTime = TextHelper.GetNullableDate (GetValueFromParams (parameters, "pEndDate"))
					}));

			case "~/REPORTS/USERS/USERSESSIONHISTORYDETAIL":

				return DataHelper.ToDataSet (AdoUserSessionLog.GetUserSessionHistory (
					new ESF.SSO.Core.Entities.User () { Alias = GetValueFromParams (parameters, "pUserAlias") }));
		}

		JS.AddWarning(Page, string.Format("La ruta de reporte {0} no esta soportada", pReportFolderPath));
		rptReportViewer.Visible = false;
		return null;
	}


	protected override Microsoft.Reporting.WebForms.ReportViewer GetReportViewerInstance()
	{
		return rptReportViewer;
	}

	#endregion
}